import * as THREE from 'three'
import GUI from 'lil-gui'
import Stats from 'three/examples/jsm/libs/stats.module.js'
import Base3D from '../index'
export default class Debug {
  constructor() {
    this.base3D = Base3D.getInstance()
    this.axesHelper
    this.gridHelper
    this.stats
    this.init()
  }

  init() {
    if (this.base3D.options.debug) {
      console.error('init  Debug========>')
      this.createGui()
      this.createAxesHelper()
      this.createGrid()
      this.createPerformanceListen()
    }
  }

  // 调试器
  createGui() {
    console.error('init  GUI========>')
    this.gui = new GUI()
  }

  // 创建坐标系
  createAxesHelper(width) {
    console.error('init  AxesHelper========>')
    this.axesHelper = new THREE.AxesHelper(width || 500)
    // this.axesHelper.position.z = 1
    this.base3D.scene.add(this.axesHelper)
  }

  // 创建辅助栅格
  createGrid(arr) {
    console.error('init  GridHelper========>')
    let arg = arr || [300, 20, 0xbbbb2b, 0x1d2129]
    this.gridHelper = new THREE.GridHelper(...arg)
    this.gridHelper.position.y = -1
    // this.gridHelper.rotation.x = Math.PI / 2
    this.base3D.scene.add(this.gridHelper)
  }

  // 性能检测
  createPerformanceListen() {
    console.error('init  PerformanceListen========>')
    this.stats = new Stats()
    this.stats.setMode(0)
    this.stats.domElement.style.position = 'absolute'
    this.stats.domElement.style.left = '0px'
    this.stats.domElement.style.top = '0px'
    document.body.appendChild(this.stats.domElement)
  }
}
